package com.cloudbroker.bcs.csvc.itn.api.utils;

import com.cloudbroker.bcs.csvc.itn.api.constants.ITNErrorCodes;
import com.cloudbroker.bcs.csvc.itn.api.constants.ITNFields;

import java.util.HashMap;
import java.util.Map;

public class ITNUtil {
    
    public static boolean isSuccess(Map<String, Object> result) {
        if (null != result) {
            Object error_no = result.get(ITNFields.ERROR_NO);
            return null == error_no || ITNErrorCodes.SUCCESS.equals(String.valueOf(error_no));
        }
        return false;
    }
    
    public static Map<String, Object> genCommErrorResult() {
        Map<String, Object> result = new HashMap<String, Object>();
        result.put(ITNFields.ERROR_NO, "-1");
        result.put(ITNFields.ERROR_INFO, "Execute Error.");
        return result;
    }
    
    public static Map<String, Object> genErrorResult(int errorNo, String errorInfo) {
        Map<String, Object> result = new HashMap<String, Object>();
        result.put(ITNFields.ERROR_NO, errorNo);
        result.put(ITNFields.ERROR_INFO, errorInfo);
        return result;
    }
    
    public static Map<String, Object> genSuccessResult() {
        Map<String, Object> result = new HashMap<String, Object>();
        return setSuccessResult(result);
    }
    
    public static Map<String, Object> setSuccessResult(Map<String, Object> map) {
        map.put(ITNFields.ERROR_NO, ITNErrorCodes.SUCCESS);
        map.put(ITNFields.ERROR_INFO, "Execute success.");
        return map;
    }
    
    public static Map<String, Object> setSuccessResult(Map<String, Object> map, String errorInfo) {
        map.put(ITNFields.ERROR_NO, ITNErrorCodes.SUCCESS);
        map.put(ITNFields.ERROR_INFO, errorInfo);
        return map;
    }
    
    public static Map<String, Object> setErrorResult(Map<String, Object> map, int errorNo, String errorInfo) {
        map.put(ITNFields.ERROR_NO, errorNo);
        map.put(ITNFields.ERROR_INFO, errorInfo);
        return map;
    }
    
}
